package com.example.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.example.entity.SecurityTipRecord;
import com.example.ext.entity.ExtPromotionRecord;
import com.example.service.PromotionService;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * Created by douyx on 2018/03/19.
 */
@RestController
@RequestMapping("api/promotion")
public class PromotionController {

	@Autowired
	private PromotionService promotionService;

	/**
	 * 阅读安全提示加积分
	 * 
	 * @param map
	 *            userId: 用户编号
	 *            type: 3 电梯安全管理员 4 维保员
	 *            tipId: 安全提示编号
	 * @return
	 */
	@ApiOperation(value = "阅读安全提示加积分", notes = "阅读安全提示加积分")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "tipId", value = "安全提示编号", required = true, dataType = "String") })
	@RequestMapping(value = "/addByRead", method = RequestMethod.POST)
	Map<String, Object> addEmpiricByReadTip(@RequestBody SecurityTipRecord securityTipRecord) {
		return promotionService.addEmpiricByReadTip(securityTipRecord);
	}

	/**
	 * 上传1份电梯安全管理制度中的资料
	 * 
	 * @param map
	 *            type: 1 维保单位 2 物业单位
	 *            partyId: 单位编号
	 *            empiricValue: 经验值
	 *            content: 加分项目 上传1份电梯安全管理制度中的资料,删除1份电梯安全管理制度中的资料
	 * @return
	 */
	@ApiOperation(value = "上传1份电梯安全管理制度中的资料", notes = "上传1份电梯安全管理制度中的资料")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "1 维保单位 2 物业单位", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyId", value = "单位编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "empiricValue", value = "经验值", required = true, dataType = "String"),
			@ApiImplicitParam(name = "content", value = "加分项目", required = true, dataType = "String") })
	@RequestMapping(value = "/addByUpload", method = RequestMethod.POST)
	Map<String, Object> addByUpload(@RequestBody Map<String, Object> param) {
		return promotionService.addByUpload(param);
	}

	/**
	 * 上传专业证书加经验
	 * 
	 * @param map
	 *            type: 3 电梯安全管理员 4 维保员  (必输)
	 *            userId: 用户编号 (必输)
	 * @return
	 */
	@ApiOperation(value = "上传专业证书加经验", notes = "上传专业证书加经验")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "String") })
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	Map<String, Object> addEmpiricByCert(@RequestBody Map<String, Object> param) {
		return promotionService.addEmpiricByCert(param);
	}

	/**
	 * 监管部门打分
	 * 
	 * @param map
	 *            type: 1 维保单位 2 物业单位
	 *            partyId: 单位编号
	 *            empiricValue: 经验值
	 * @return
	 */
	@ApiOperation(value = "监管部门打分", notes = "监管部门打分")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "1 维保单位 2 物业单位", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyId", value = "单位编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "empiricValue", value = "经验值", required = true, dataType = "String") })
	@RequestMapping(value = "/addEmpiric", method = RequestMethod.POST)
	Map<String, Object> addEmpiric(@RequestBody Map<String, Object> param) {
		return promotionService.addEmpiric(param);
	}

	/**
	 * 用户转移经验同步转移
	 * 
	 * @param map
	 *            userId: 用户编号 (必输)
	 *            type: 3 电梯安全管理员 4 维保员  (必输)
	 *            partyIdBfr: 转移前机构编号 (必输)
	 *            partyTypeBfr: 1 维保单位 2 物业单位  (必输)
	 *            partyIdAft: 转移后机构编号 (必输)
	 *            partyTypeAft: 1 维保单位 2 物业单位  (必输)
	 * @return
	 */
	@ApiOperation(value = "用户转移经验同步转移", notes = "用户转移经验同步转移")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "userId", value = "用户编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "type", value = "3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyIdBfr", value = "转移前机构编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyTypeBfr", value = "1 维保单位 2 物业单位", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyIdAft", value = "转移后机构编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "partyTypeAft", value = "1 维保单位 2 物业单位", required = true, dataType = "String")})
	@RequestMapping(value = "/empiricTrans", method = RequestMethod.POST)
	Map<String, Object> empiricTrans(@RequestBody Map<String, Object> param) {
		return promotionService.empiricTrans(param);
	}

	/**
	 * 查询成就及经验值
	 * 
	 * @param map
	 *            type: 1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员 (必输)
	 *            userId: 用户编号/单位编号(必输)
	 * @return empiricValue: 经验值 
	 *         grade: 等级 
	 *         achieves: 成就列表（List<String>）
	 */
	@ApiOperation(value = "查询成就及经验值", notes = "查询成就及经验值")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户编号/单位编号", required = true, dataType = "String") })
	@RequestMapping(value = "/query", method = RequestMethod.POST)
	Map<String, Object> query(@RequestBody Map<String, Object> param) {
		return promotionService.query(param);
	}

	/**
	 * 排行榜查询
	 * 
	 * @param map
	 *            type: 排名维度：1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员 (必输)
	 *            userId: 用户编号/单位编号
	 *            parentId: 需要查询下辖排行的区域单位编号(必输)
	 * @return userName: 用户名称 
	 *         ranking: 排名 
	 *         partyName: 单位名称 
	 *         empiricValue: 经验值 
	 *         grade: 等级  (单位无此字段)
	 *         achieve: 成就 (单位无此字段)
	 *         rankings: 排名列表（List<Map<String, Object>> 前十名 Map中包含上述字段）
	 */
	@ApiOperation(value = "排行榜查询", notes = "排行榜查询")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "排名维度：1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户编号/单位编号(可为空)", required = true, dataType = "String"),
			@ApiImplicitParam(name = "parentId", value = "需要查询下辖排行的区域单位编号", required = true, dataType = "String") })
	@RequestMapping(value = "/ranking", method = RequestMethod.POST)
	Map<String, Object> queryRanking(@RequestBody Map<String, Object> param) {
		return promotionService.queryRanking(param);
	}

	/**
	 * 排行榜查询
	 * 
	 * @param map
	 *            type: 排名维度：1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员 (必输)
	 * @return 
	 *         rankings: 排名列表（List<Map<String, Object>> 前十名 Map中包含上述字段）
	 * 	       	userName: 用户名称 
	 *  	    ranking: 排名 
	 *   	    partyName: 单位名称 
	 *          empiricValue: 经验值 
	 *   	    grade: 等级  (单位无此字段)
	 *     	    achieve: 成就 (单位无此字段)
	 */
	@ApiOperation(value = "排行榜查询", notes = "排行榜查询")
	@ApiImplicitParam(name = "type", value = "排名维度：1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员", required = true, dataType = "String")
	@RequestMapping(value = "/ranks", method = RequestMethod.POST)
	Map<String, Object> queryRanks(@RequestBody Map<String, Object> param) {
		return promotionService.queryRanks(param);
	}

	/**
	 * 查询加分记录
	 * 
	 * @param map
	 *            type: 1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员 (必输)
	 *            userId: 用户编号/单位编号(必输)
	 *            addedTimeFrom: 加分时间开始(可选)
	 *            addedTimeTo: 加分时间结束(可选)
	 * @return PromotionRecord
	 */
	@ApiOperation(value = "查询加分记录", notes = "查询加分记录")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "type", value = "1 维保单位 2 物业单位 3 电梯安全管理员 4 维保员", required = true, dataType = "String"),
			@ApiImplicitParam(name = "userId", value = "用户编号/单位编号", required = true, dataType = "String"),
			@ApiImplicitParam(name = "addedTimeFrom", value = "加分时间开始", required = true, dataType = "String"),
			@ApiImplicitParam(name = "addedTimeTo", value = "加分时间结束", required = true, dataType = "String")})
	@RequestMapping(value = "/queryRecord", method = RequestMethod.POST)
	Map<String, Object> queryRecord(@RequestBody ExtPromotionRecord promotionRecord) {
		return promotionService.queryRecord(promotionRecord);
	}
}
